import {WindowName} from "../../framework/reflect/WindowName";
import CommonUtil from "../../framework/utils/CommonUtil";
import DecorView from "../../framework/DecorView";
import Context from "../../framework/Context";

const {ccclass, property} = cc._decorator;

@ccclass
@WindowName("AchieveToast")
export default class AchieveToast extends DecorView {

    public static showToast(msg: string) {
        Context.get().attachDecor(AchieveToast).then(decor => {
            decor.setMsg(msg);
        })
    }

    @property(cc.Label)
    private msgBgLabel: cc.Label = null;

    @property(cc.Label)
    private msgLabel: cc.Label = null;

    public setMsg(msg: string) {
        this.msgBgLabel.string = this.msgLabel.string = msg;
    }

    public onShow() {
        this.msgBgLabel.node.x -= 500;
        CommonUtil.runAction(this.msgBgLabel, cc.moveBy(0.5, 500, 0).easing(cc.easeElasticIn(2))).then(() => {
            return CommonUtil.delay(1.5);
        }).then(() => {
            return CommonUtil.runAction(this, cc.fadeOut(0.3));
        }).then(() => {
            this.finish();
        });
    }

    protected async beforeShowing(): Promise<any> {

    }
}

